/**
 * 
 */
package io.dora.demo;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

/**
 * @author zhaohongbo
 *
 */
public class ForTest {
	
	/**检测输入是否为数字
	 * @return
	 */
	public String isInputNumber(String ids){
		String[] goodsIdArray = StringUtils.split(ids, ",");
		Pattern pattern = null;
		Matcher matcher = null;
		for(String goodsId : goodsIdArray){
			pattern = Pattern.compile("\\d+");
			matcher = pattern.matcher(goodsId);
			if(matcher.matches()){
				try{
					Long.parseLong(goodsId.trim());
				}catch(Exception e){
					return "商品编号"+goodsId+"输入错误！";
				}
				continue;
			}
			return "商品编号"+goodsId+"包含非法字符，请重新输入！";
		}
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ForTest ft = new ForTest();
		System.out.println(ft.isInputNumber("100000001004"));
	}

}
